package validator.handle;

import java.lang.annotation.Annotation;
import java.text.SimpleDateFormat;

import validator.annotation.Time;
import validator.exception.ValidateException;

public class TimeValidator implements Validator {

	@Override
	public boolean isValid(Class<?> clazz) {
		return CharSequence.class.isAssignableFrom(clazz);
	}

	@Override
	public void validate(Annotation annotation, Object v) {
		Time anno = (Time) annotation;

		try {
			SimpleDateFormat df = new SimpleDateFormat(anno.format());
			df.parse(v.toString());
		} catch (Exception e) {
			throw new ValidateException(anno.value(), e);
		}
	}

}
